
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
 
const char* host = "djxmmx.net";
const int port = 17;              

ESP8266WiFiMulti multi; 

void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);//默认就是sta模式 可以注释掉此行

  multi.addAP("wsm","WSM19900509");
  multi.addAP("MERCURY_394B46", "wifi19900509wifi"); 
 
  while (multi.run() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.print("WiFi Connected! IP address:  ");
  Serial.print(WiFi.localIP());

  wifiClientRequest();  
}
 
void loop(){
}
 
void wifiClientRequest(){
  WiFiClient client;    
  String httpRequest =  String("GET /") + " HTTP/1.1\r\n" +
                        "Host: " + host + "\r\n" +
                        "Connection: close\r\n" +
                        "\r\n";
  
  
  if (client.connect(host, port)){ 
    client.print(httpRequest);          // 向服务器发送HTTP请求
    Serial.println("Web Server Response:"); 
    while (client.connected() || client.available()){ 
      if (client.available()){
        String line = client.readStringUntil('\n');
        Serial.println(line);
      }
    }
    client.stop();                      // 断开与服务器的连接
  } else{   
    Serial.println(" request failed!");
    client.stop();
  } 

}
